package com.li.shanlin.task;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author liyinlong
 *
 * 2017年5月9日上午11:48:15
 */
@Component
@Configurable
@EnableScheduling
public class ScheduledTasks{
	private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
    @Scheduled(fixedRate = 1000 * 30)
    public void reportCurrentTime(){
        log.info("30秒执行一次的心跳task: The time is now " + dateFormat ().format (new Date ()));
    }

    //每1分钟执行一次
    @Scheduled(cron = "5 * * * * ? ")
    public void reportCurrentByCron(){
    	log.info("5秒执行一次的taskCron: The time is now " + dateFormat ().format (new Date ()));
    }

    private SimpleDateFormat dateFormat(){
        return new SimpleDateFormat ("HH:mm:ss");
    }
    
}
